package com.gqz.aircraftwar.util

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.util.LruCache
import com.gqz.aircraftwar.App

/**
 * Descraption
 *
 * @author gqz
 * @data 2020/4/3
 */
object BmpCache {
    private val TAG: String = "BmpCache-->"

    val maxMem = Runtime.getRuntime().maxMemory()
    val size = (maxMem / 8).toInt()
    val cache = LruCache<Int, Bitmap>(size)

    fun loadBmp(resId: Int): Bitmap {
        var bmp = cache.get(resId)
        if (bmp == null) {
            bmp = BitmapFactory.decodeResource(App.instance.resources, resId)
            cache.put(resId, bmp)
        }
        return bmp
    }
}